home *** CD-ROM | disk | FTP | other *** search
- /**********************************************
- A Simple password program written using
- Borland's Turbo C++ for DOS v3.0.
- Written by: Michael J. Campbell, 1994
-
- Note: Still not using all the new techniques
- and classes yet. I still seem to be
- stuck doing C stuff, especially in I/O.
- **********************************************/
-
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <graphics.h>
- #include <dos.h>
- #include <conio.h>
-
- //Initialize functions
- extern void set_graph(void);
- extern void set_up(void);
- extern void wait(void);
- extern void change(void);
- extern int ESC_pressed;
- extern void write_text(int,int,int,int,int,int,int);
-
- char text[30]; //Global temporary text variable
- char password[30];
-
- void main(void)
- {
- int tries=0;
- FILE *fp;
-
- // Disable control-break keypress
- setcbrk(0);
-
- // Change to graphics mode
- set_graph();
-
- // The old style for doing files
- if((fp = fopen("c:\\allow.use","r")) == NULL)
- {
- fp = fopen("c:\\allow.use","w+");
- fprintf(fp,"DEFAULT\0");
- fclose(fp);
- setcolor(WHITE);
- settextjustify(LEFT_TEXT,CENTER_TEXT);
- outtextxy(120,200,"INITIAL PASSWORD IS 'DEFAULT', YOU SHOULD CHANGE THIS.");
- outtextxy(120,220,"THE PASSWORD IS CASE-SENSITIVE. IT CAN INCLUDE SPACES");
- outtextxy(120,240,"AND ALL ASCII CHARACTERS.");
- outtextxy(120,260,"THE PASSWORD WILL BE KEPT IN YOUR ROOT DIRECTORY IN THE");
- outtextxy(120,280,"FILE 'ALLOW.USE'. IF YOU DELETE THIS FILE, THIS SCREEN");
- outtextxy(120,300,"WILL BE DISPLAYED AGAIN. YOU CAN ALSO MAKE IT A HIDDEN");
- outtextxy(120,320,"FILE FOR FURTHER PROTECTION. PRESS ANY KEY TO CONTINUE...");
- settextjustify(CENTER_TEXT,CENTER_TEXT);
-
- getch();
- cleardevice();
- }
-
- // Get password
- fp = fopen("c:\\allow.use","r");
- fscanf(fp,"%s",&password);
- fclose(fp);
-
- // Prompt user for password loop
- while(1)
- {
- // Draw input box
- set_up();
- // Increment user tries
- tries++;
-
- write_text(267,242,BLACK,BLACK,LIGHTGRAY,15,0);
-
- // If password matches, exit
- if(strcmp(text,password) == 0) { restorecrtmode(); break; }
-
- // If user wants to change password
- if(strcmp(text,"CHANGE") == 0)
- {
- ESC_pressed = 0;
- change();
-
- // Get new password
- fp = fopen("c:\\allow.use","r");
- fscanf(fp,"%s",&password);
- fclose(fp);
- tries--;
- }
-
- // Slap user on hand for not knowing password
- if(tries > 2)
- {
- wait();
- tries = 0;
- }
- }
-
- exit(1);
- }
-
-